package com.psd.demo.controller;

import java.util.List;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.pds.demo.dao.OrganizationDao;
import com.pds.demo.dao.impl.OrganizationDaoImpl;
import com.pds.mvc.ActionForward;
import com.pds.mvc.Actions;
import com.psd.demo.model.OrgAllList;
import com.psd.demo.model.Organization;
import com.psd.demo.model.User;

public class SearchByIdEmpUpdateServlet extends Actions {

	@Override
	public ActionForward execute(HttpServletRequest request,
			HttpServletResponse response) {
		// 告诉服务器，对表单进行中文解码
		response.setContentType("text/html;charset=utf-8");
		// 接受前台的参数ID
//		int orgid=Integer.parseInt(request.getParameter("orgid"));
//		System.out.println("从前台接受的Org_ID:"+orgid);
		int id = Integer.parseInt(request.getParameter("id"));
		

		String sql = "SELECT U.USER_ID 序号,U.USER_NAME 用户名,"
				+ "U.USER_PASS 密码,O.ORG_NAME 机构名称,"
				+ "D.DEP_NAME 部门名称,REAL_NAME 真实姓名,"
				+ "USER_AGE 年龄,USER_SEX 性别,USER_COLLEGE 学历," + "REG_TIME 注册时间 "
				+ "FROM USER U ,department D,organization O "
				+ "where U.DEP_ID = D.DEP_ID AND U.ORG_ID=O.ORG_ID  "
				+ "and USER_ID=? ";
		OrganizationDao dao = new OrganizationDaoImpl();
		try {
			OrgAllList org = dao.SearchById(sql, id);
			this.setRequestPage("updateemplist", org, request);
			
			List<Organization> orglistselectoption = dao.getOrgListSelectOption();
			this.setRequestPage("selectoption", orglistselectoption, request);
			System.out.println("orglistselectoption:"+orglistselectoption.size());
			return new ActionForward("./update.jsp", true);
		} catch (Exception e) {
			e.printStackTrace();
		}
		return new ActionForward("./error.jsp", true);

	}

}
